<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="#">社团管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>申请列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--  输入框组-->
    <div>
      <br/>
      <span>姓名 &nbsp;&nbsp;</span>
      <el-input
          placeholder="请输入姓名"
          prefix-icon="el-icon-search"
          v-model="name" class="inputMax" >
      </el-input>
      &nbsp;&nbsp;
      <el-button type="primary" icon="el-icon-search" @click="applicantSearch" ><span>查询</span></el-button>
      <br/>
      <br/>
    </div>
    <el-table
        :data="applicants"
        border
        style="width: 100%">
      <el-table-column
          prop="id"
          label="ID"
          width="100">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="100">
      </el-table-column>
      <el-table-column
          prop="email"
          label="邮箱">
      </el-table-column>
      <el-table-column
          prop="content"
          show-overflow-tooltip
          label="申请内容">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="申请时间">
        <template slot-scope="scope">
          <span>{{scope.row.createTime | DateFormat}}</span>
        </template>
      </el-table-column>
      <el-table-column
          fixed="right"
          width="180"
          label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="toApplicantPass(scope.row)">通过</el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="open(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pagesize"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
import {
  applicantList,
  applicantPass,
  applicantDelete
} from '@/api'
export default {
  name: "Applicant",
  components: {
  },
  data() {
    return {
      name: '',
      applicants: [],
      c_id: sessionStorage.getItem('cid'),
      total: 0,
      pagesize: 5,
    }
  },

  created() {
    let applicant = {c_id: this.c_id};
    applicantList(applicant).then((result)=>{
      this.applicants = result.data.list;
      this.total = result.data.total;
      this.pagesize = result.data.pagesize;
    })
  },

  methods: {
    applicantSearch(){
      let applicant = {
        name: this.name,
        c_id: this.c_id,
      };
      applicantList(applicant).then((result)=>{
        this.applicants = result.data.list;
        this.total = result.data.total;
        this.pagesize = result.data.pagesize;
      });
    },

    // 通过 申请
    toApplicantPass(applicant){
      let applicant1 = {
        id: applicant.id,
        name: applicant.name,
        email: applicant.email,
        c_id: this.c_id
      };
      applicantPass(applicant1).then(()=>{
        this.$message.success("加入成功");
        applicantList({c_id:this.c_id}).then((result)=>{
          this.applicants = result.data.list;
          this.total = result.data.total;
          this.pagesize = result.data.pagesize;
        });
      })
    },

    open(id) {
      this.$confirm('此操作将永久删除该申请, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let applicant = {
          id: id,
        };
        applicantDelete(applicant).then(()=>{
          applicantList({c_id:this.c_id}).then((result)=>{
            this.applicants = result.data.list;
            this.total = result.data.total;
            this.pagesize = result.data.pagesize;
          });
        })
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  }
}
</script>

<style scoped>
.inputMax{
  width: 200px;
}
</style>
